<?php
include_once('common/header.php');
if($AppUI->id <=0 || ($AppUI->id > 0 && $AppUI->type < 1) || (isset($_SESSION['admin']) && ($_SESSION['admin']&1<<2)==0)) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 		= $objRequest->getParams();
$intAdminId		= isset($arrParams['padminid']) ? $arrParams['padminid'] : 0;
$strUsername	= isset($arrParams['pusername']) ? $arrParams['pusername'] : '';
$objAdmin 		= new Admin();
$arrSection		= $objAdmin->getSection();
$arrPerms		= array();
$intError		= 0;
if($arrSection) {
	foreach($arrSection as $row) {
		$arrPerms[$row['sectionid']] = Vfriend_Function::convertArrToInt($arrParams['pPerm'.$row['sectionid']]);
	}
}
if($arrPerms) {
	foreach($arrPerms as $key=>$value) {			
		$intError = $objAdmin->addAdPermission($AppUI->id, $intAdminId, $key, $value);			
		if($intError > 0) {
			break;
		}
	}
}
if($intError > 0) {
	Vfriend_Function::setError($arrError[18]);
	Vfriend_Function::redirect(HOST_BACKEND . 'index/permission');
} else {
	$strMessage	= $arrMessage[6];
	$strMessage	= str_replace('#strUsername#', $strUsername, $strMessage);
	Vfriend_Function::setMsg($strMessage);
	Vfriend_Function::redirect(HOST_BACKEND . 'index/list');
}
?>